* ========================================
* Immmigrant shares and Attitudes by Party
* ========================================


* Immigrant fraction of candidates
* ================================

	use $dta\ImportPoliticians.dta, clear
	keep if running_loc
	
	* Import coutry background
	merge m:1 idPers using  $dta\ImportPers.dta, keep(matched) nogen

	collapse immigrant, by(party_loc)
	rename immigrant partyImmigrants
	tempfile immshare
	save `immshare'
	
	
* Survey on immigrant attitudes
* =============================

	use $dta_ext\Survey2015.dta, clear

	keep T50a T07
	drop if T07 > 9 // non-big nine parties
	gen partyAttitudes = 1*(T50a == 1) // friendliness to immigrants
	gen party_loc = ""
	replace party_loc = "rodt" if T07 == 1
	replace party_loc = "sv" if T07 == 2
	replace party_loc = "a" if T07 == 3
	replace party_loc = "sp" if T07 == 4		
	replace party_loc = "krf" if T07 == 5
	replace party_loc = "v" if T07 == 6
	replace party_loc = "h" if T07 == 7
	replace party_loc = "frp" if T07 == 8		
	replace party_loc = "mdg" if T07 == 9		
	
	gen partyBloc = "Left" if party_loc == "rodt" | party_loc == "sv" | ///
		party_loc == "a"  | party_loc == "sp"  | party_loc == "mdg"
	replace partyBloc = "Right" if party_loc == "krf" | party_loc == "v" | ///
		party_loc == "h" | party_loc == "frp" 
	
	collapse partyAttitudes, by(party_loc partyBloc)

	
* Combine
* =======

	merge 1:1 party_loc using `immshare', keep(master matched) nogen
	
	save $dta\SurveyAttitudes.dta, replace
